<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@page import="java.util.*"%>
<%@page import="com.srit.core.bean.Page" %>
<%@page import="com.srit.map.business.bean.Company" %>
<%
	String path= request.getContextPath();
	System.out.print(path);
	String basePath = request.getScheme() + "://"    + request.getServerName() + ":" + request.getServerPort()    + path + "/";
%>
<html>
<head>
<title>地图搜索</title>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
<script type="text/javascript" src="<%=path %>/pages/admin/easyui/jquery-1.8.0.min.js"></script>
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
#l-map{height:100%;width:78%;float:left;border-right:2px solid #bcbcbc;}
#right{height:100%;width:20%;float:left;}
.icon_right{background:url(./image/markers.png);width:19px;height:25px}
</style>
<%
//jsp得到page对象
Page pages = (Page)request.getAttribute("page");
int len = 0;
int total = 0;
List<Company> companyList = new ArrayList<Company>();
if(pages.getList() != null){
	companyList = pages.getList();
	len = companyList.size();
	total = pages.getTotalNum();
}

%>
</head>
<body>
<s:form action="mapSearch!searchByKey.do" namespace="/pages/admin" method="post">
<s:text name="search" > 输入搜索字段：</s:text>
<input type="text" id="searchKey" name="searchKey" size="15"></input>
<input type="submit" value="提交"/> 
</s:form>
<div id="allmap">
	<div id="l-map"></div>
	<div id="right">
		<%=total %>个搜索结果
			<%for(int j = 0; j < len; j ++) {
				%>
				<div>
					<div class="icon_right" ></div> 
					
				<%=companyList.get(j).getName()%></div>
				<% 
			}%>
		<s:if test="page.pageNum>0">
		<s:a namespace="/pages/admin" action="mapSearch" method="searchByKey">
			<s:param name="page.pageNum" value="page.pageNum-1"></s:param>
			<s:param name="searchKey" value="page.sp.searchKey"></s:param>
								上一页
							</s:a>
		</s:if>
		<s:if test="page.pageNum<page.totalPage-1">
		<s:a namespace="/pages/admin" action="mapSearch" method="searchByKey">
			<s:param name="page.pageNum" value="page.pageNum+1"></s:param>
			<s:param name="searchKey" value="page.sp.searchKey"></s:param>
								下一页
							</s:a>
		</s:if>
	</div>
</div>
</body>
</html>
<!-- 地图初始化 -->
<script type="text/javascript">
var map = new BMap.Map("l-map");
var point = new BMap.Point(121.559243,29.825056);
map.centerAndZoom(point,15);
map.addControl(new BMap.NavigationControl()); //添加默认缩放平移控件
map.enableScrollWheelZoom();    //启用滚轮放大缩小，默认禁用

if('<%=len%>' > 5)
{
	map.setZoom(12);	
}
<%
for(int i = 0; i < len; i ++) {%>
	var x='<%=companyList.get(i).getPost_long()%>';
	var y='<%=companyList.get(i).getPost_lat()%>';
	//alert(x+","+y)
	var j=<%=i%>*(-25);
	//alert(j);
 	var point = new BMap.Point(x, y);
 	var myIcon = new BMap.Icon("./image/markers.png", new BMap.Size(19,25));
 	myIcon.setAnchor(new BMap.Size(9.5,25));
 	myIcon.setImageOffset(new BMap.Size(0,j));
 	var marker = new BMap.Marker(point,{icon:myIcon});
 	map.addOverlay(marker);
 	var infoWindow = new BMap.InfoWindow('<%=companyList.get(i).getName()%>');
 	marker.openInfoWindow(infoWindow);
 	marker.addEventListener("click", function(){this.openInfoWindow(infoWindow);});
<%
}
%>
</script>
<!-- 右边标识切换 A B -->
<script>
	$(document).ready(function(){
		for(i=0;i<<%=len%>;i++){
			k=-25*i;
			$(".icon_right").eq(i).css({"background-position":"-19px "+k+"px"});
		}
	});
</script>